#include "specdesign.h"
#include "specdesignl.h"

#include "earthquake_global.h"

string SpecDesign::m_objname = "SpecDesign";

SpecDesign::SpecDesign() :
    m_damping(0.05),
    m_ductility_factor(1),
    m_tp_spec(TpSpecDesign::SLS)
{

}

SpecDesign::SpecDesign(const PKeyList* plist) :
    m_damping(0.05),
    m_ductility_factor(1),
    m_tp_spec(TpSpecDesign::SLS),
    PKeyItem(plist->getListId()),
    PRef(plist)
{

}

SpecDesign::SpecDesign( const SpecDesign& s ) :
    m_damping(s.m_damping),
    m_ductility_factor(s.m_ductility_factor),
    m_tp_spec(s.m_tp_spec),
    PKey(s),
    PItem(s),
    PRef(s)
{

}

SpecDesign::SpecDesign(
        const         PKeyItem& key,
        const         PRef& ref,
        const      Damping& dam,
        const    Ductility& duc,
        const TpSpecDesign& tps
        ) :
    m_damping(dam),
    m_ductility_factor(duc),
    m_tp_spec(tps),
    PKey(key),
    PItem(key),
    PRef(ref)
{

}

SpecDesign& SpecDesign::operator = ( const SpecDesign& s )
{
    // Per la classe derivata [SpecDesign]
    m_damping = s.getDamping();
    m_ductility_factor = s.getDuctility();
    m_tp_spec = s.getTpSpecDesign();

    // Per la classe [PKey]
    // PKey::operator = ( sp );
    setKeyStr(s.getKeyStr());
    setDescr(s.getDescr());

    if ( s.getTabRef() != EXA_TAB_NULL )
    {
        setTabRef(s.getTabRef());
    }

    // Per la classe [PRef]
    PRef::operator = ( s );
    return *this;
}

const Damping& SpecDesign::getDamping( void ) const
{
    return (m_damping);
}

const Ductility& SpecDesign::getDuctility( void ) const
{
    return (m_ductility_factor);
}

void SpecDesign::setDamping( Damping& n )
{
    m_damping = n;
}

void SpecDesign::setDamping( const double& n )
{
    m_damping.setValue(n);
}

void SpecDesign::setDuctility( Ductility& d )
{
    m_ductility_factor = d;
}

void SpecDesign::setDuctility( const double& d )
{
    m_ductility_factor.setValue( d );
}

const TpSpecDesign& SpecDesign::getTpSpecDesign( void ) const
{
    return( m_tp_spec );
}

void SpecDesign::setTpSpecDesign( const TpSpecDesign& tp )
{
    m_tp_spec = tp;
}

bool SpecDesign::isComplete(void) const
{
    return (m_damping.isSet() && m_ductility_factor.isSet() && m_tp_spec.isSetFlag());
}

void SpecDesign::reportMake(const string& objname) const
{
    if (getReportCurrentStyle() == STYLE_VERBOSE)
    {
        PReport::resetReportOpt();
        PReport::setReportOpt("SUB",true);
        PKeyItem::reportMake();
        PRef::reportMake();
        PReport::setReportOpt("SUB",false);
        moveLineInBlock(string("VALORI"));
        addInLine("dumping",m_damping.getValue());
        addInLine("ductility",m_ductility_factor.getValue());
        addInLine("spectrum type",m_tp_spec.getFlagStr());
        moveLineInBlock();
    }
    else if (getReportCurrentStyle() == STYLE_COMPACT)
    {
        addInLine("ID",getKeyStr(),10);
        addInLine("des.",getDescr());
        addInLine("TAB",getTabRef(),2);
        addInLine("ni",m_damping.getValue(),3,2);
        addInLine("d",m_ductility_factor.getValue(),3,2);
        addInLine("type",m_tp_spec.getFlagStr(),3);
        addInLine("ID.Sp",getRefFrom(EXA_TAB_SPECPARAM).getKeyStr(),10);
        moveLineInBlock();
    }
    PReport::reportMake(m_objname);
}
